<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>合同模板编辑|新增</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp" %> 
  <style type="text/css">
    	div.box-body {
    		margin-top:7px;
    	}
    </style>
  
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>合同模板<%= "0".equals(request.getParameter("optType"))? "新增" : "编辑" %></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">合同管理</a></li>
            <li class="active"><a href="#">合同模板管理</a></li>
        </ol>
    </section>
    <section class="content">
    <form id="submitForm" role="form" class="form-horizontal" action="${ctx}/contractModel/saveOrUpdContractModel.html">
    	<div class=" box box-success">    			
    		      <div class="box-body">
                 	<div class="form-group form-group-xs">
                        <label for="exampleInputEmail1" class="col-sm-2 text-right"><span style="color:red">* </span>合同模板名称：</label>
                        <div class="col-sm-9 text-left">
                            <input class="form-control" name="contractModelName" id="contractModelName" placeholder="合同模板名称" type="text" maxlength="200">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="version" class="col-sm-2 text-right"><span style="color:red">* </span>版本号：</label>
                        <div class="col-sm-9 text-left">
                            <input class="form-control" name="version" id="version" placeholder="版本号" type="text" maxlength="60">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="inputTextAlter4" class="col-sm-2 text-right">模板内容：</label>
                        <div class="col-sm-9 text-left">
                            <div id="editor" style="height:400px;" name="content">
                            </div>
                        </div>
                    </div>
                    <input type="hidden" value="${optType}" id="optType" name="optType">
                    <input type="hidden" value="" id="txtContent" name="txtContent">
                    <!-- 保存项目公告id -->
                    <input type="hidden" value="${contractModel.contractModelId}" id="contractModelId" name="contractModelId">
                </div>
                <div class="box-footer text-center">
                    <a onclick ="save()" class="btn btn-success btn-sm">保&nbsp;存</a>
                    <a onclick ="back()" class="btn btn-danger btn-sm">返&nbsp;回</a>
                </div>
        	</div>
        </form>	
    </section>
     <%@ include file="/WEB-INF/component/commonJS.jsp" %>  
     <script src="${ctx}/lib/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>
    <script type="text/javascript">
        var ue;
        function save(){
        	if(!validate()){
        		return;
        	}
    		$.HN.message.confirm('确定要保存吗？', '', '').on(function (e) {
                   if (e) {
                var ue = UE.getEditor('editor');
                var txtContent = ue.getContentTxt();
                $("#txtContent").val(txtContent)
    			$("#submitForm").ajaxSubmit({
    				 type: 'post',
    				dataType : "json",
    				timeout: 10000,
    				success : function(result) {
    					if (result.success) {
    						$.HN.message.alert("保存成功！", "消息", "success", function() {
    							window.location.href="${ctx}/contractModel/toContractModelList.html";
    						});
    					} else {
    						$.HN.message.alert(result.msg || "", "消息", "error");
    					}
    				}
    			});
             }
           });
        }
        function validate(){
        	var contractModelName = $.trim($("#contractModelName").val());
    		if (contractModelName == null || contractModelName == "") {
    			$.HN.message.alert("合同模板名称不能为空！", "消息", "warn");
    			return false;
    		} 

    		var version = $.trim($("#version").val());
    		if (version == null || version == "") {
    			$.HN.message.alert("版本号不能为空", "消息", "warn");
    			return false;
    		}
    		return true;
        }
        
        function back(){
        	window.location.href="toContractModelList.html"
        }
		$(function() {
		    ue = UE.getEditor('editor');
		    var optType = "${optType}";
			ue.ready(function() {
				 if(optType=="1"){
					 $("#contractModelName").val("${contractModel.contractModelName}");
		        	 $("#version").val("${contractModel.version}");
		             ue.setContent("${contractModel.content}"); 
				} 
			  
			});
		});
    </script>
</body>
</html>
